package com.xxx.file;

import java.io.*;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/22 15:40
 * @Copyright 博为峰
 */
public class BufferedInOutDemo {
    public static void main(String[] args) throws IOException {
//        m1();
        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("./IO/fos.txt")); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("./IO/fos2.txt"));) {
            byte[] bytes = new byte[1024];
            int count = 0;
            while ((count = bufferedInputStream.read(bytes)) != -1) {
                bufferedOutputStream.write(bytes, 0, count);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void m1() throws IOException {
        FileInputStream fileInputStream = new FileInputStream("./IO/fos.txt");
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        byte[] bytes = new byte[1024];
        int count = 0;

        //---------------------------------------------------------------------------------
        FileOutputStream fileOutputStream = new FileOutputStream("./IO/fos2.txt");
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);

        while ((count = bufferedInputStream.read(bytes)) != -1) {
            bufferedOutputStream.write(bytes, 0, count);
        }

        bufferedInputStream.close();
        bufferedOutputStream.close();
    }
}
